/**
 * 
 */
package com.calf.module.loan.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.calf.cn.aspect.MethodLog;
import com.calf.cn.controller.BaseController;
import com.calf.cn.entity.DataTables;
import com.calf.cn.service.BaseManager;
import com.calf.cn.utils.SearchUtil;
import com.calf.cn.utils.UUIDUtils;
import com.calf.module.loan.entity.ThemeType;

/**
 * @ClassName BankController
 * @Description Description
 * @author cx
 * @Date 2017年3月9日 下午3:55:04
 * @version 1.0.0
 */

@Controller
@RequestMapping(value = "/themeType")
public class ThemeTypeController implements BaseController<ThemeType> {

	@Autowired
	private BaseManager baseManager;

	/*
	 * (非 Javadoc) Description:
	 * 
	 * @see com.calf.cn.controller.BaseController#home()
	 */
	@Override
	public String home() {
		return "credit/themeType/themeTypelist";
	}

	/*
	 * (非 Javadoc) Description:
	 * 
	 * @see com.calf.cn.controller.BaseController#initTable(javax.servlet.http.
	 * HttpServletRequest)
	 */
	@Override
	public DataTables<ThemeType> initTable(HttpServletRequest request) {
		Map<String, Object> parameters = SearchUtil.convertorEntitysToMap(request.getParameterMap());
		String title = (String) parameters.get("title");
		System.out.println(title);
		String sEcho = (String) parameters.get("sEcho");
		List<ThemeType> themeType = baseManager.query(ThemeType.class, parameters);
		int total = baseManager.get("ThemeType.queryCount", parameters);
		return new DataTables<ThemeType>(sEcho, themeType, themeType.size(), total);
	}

	/*
	 * (非 Javadoc) Description:
	 * 
	 * @see com.calf.cn.controller.BaseController#addAndUpdateHome(org.
	 * springframework.ui.Model, java.lang.String)
	 */

	@Override
	public String addAndUpdateHome(Model model, String id) {
		if (StringUtils.isNotBlank(id)) {
			model.addAttribute("entity", baseManager.get("ThemeType.getThemeTypeById", new Object[] { id }));
		}
		return "credit/themeType/addThemeType";
	}
	/*
	 * 
	 * (non-Javadoc)
	 * 
	 * @see com.calf.cn.controller.BaseController#saveAdd(java.lang.Object)
	 */
	@Override
	public int saveAdd(ThemeType entity) {
		Subject currentUser = SecurityUtils.getSubject();
		entity.setThemeBankId(UUIDUtils.getUUID());
		return baseManager.insert(entity);
	}

	/*
	 * (非 Javadoc) Description:
	 * 
	 * @see com.calf.cn.controller.BaseController#delete(java.lang.Long)
	 */
	@Override
	public int delete(Long id) {
		return baseManager.delete(ThemeType.class, new Object[] { id });
	}

	@Override
	public int delete(String id) {
		return baseManager.delete(ThemeType.class, new Object[] { id });
	}

	/*
	 * (非 Javadoc) Description:
	 * 
	 * @see com.calf.cn.controller.BaseController#saveUpdate(java.lang.Object)
	 */
	@Override
	public int saveUpdate(ThemeType entity) {
		Subject currentUser = SecurityUtils.getSubject();
		return baseManager.update(entity);
	}
}
